### Include common Makefile configuration
#
include   $(top_srcdir)/build/Makefile.am.common



### Local configuration changes
#
AUTOMAKE_OPTIONS = foreign subdir-objects
ACLOCAL_AMFLAGS = -I build/m4



### Subdir processing order
#
# Process etc/ before other subdirs
#
# If Snoopy has config file enabled, then there is a small time frame
# between installation of library and subsequent installation of
# initial configuration file where ini parsing library emits an error about
# configuration file not being found. Therefore we first install
# configuration file and only then the Snoopy library itself.
#
# Also, lib/ must be processed before src/, as ini parsing library is needed
# there if config file is enabled.
#
SUBDIRS  =
if CONFIGFILE_ENABLED
SUBDIRS += etc
endif
SUBDIRS += lib
SUBDIRS += src
SUBDIRS += util
SUBDIRS += doc
SUBDIRS += tests



### Additional files to distribute in distribution package
#
EXTRA_DIST = \
	dev-tools/libexec/get-release-version.sh \
	README.md



### Make check aliases
#
checks: check
test:   check
tests:  check



### Enable/disable targets
#
enable: install
	echo ; \
	$(top_builddir)/util/snoopy-enable ; \
	echo ;

disable:
	echo ; \
	$(top_builddir)/util/snoopy-disable \
	echo ;

# Disable it if we are uninstalling it, to avoid error messages
# about missing library that should be preloaded.
uninstall-local: disable



### Clean these files additionally
#

# Clean release files
if CODE_COVERAGE_ENABLED
clean-local: coverage-clean
else
clean-local:
endif
	rm -rf snoopy-[0-9].[0-9].* ; \
	rm -f  snoopy-*.tar.gz* ; \
	rm -f  snoopy-latest-*.txt ; \
	find . -name '*.gcno' | xargs -r rm ; \
	rm -rf cov-int* ; \
	rm -rf sonarcloud-build-wrapper-output ; \
	rm -rf sonar-cfamily.reproducer ; \
	rm -rf .scannerwork ;

# Clean all files that were generated by bootstrap.sh and/or autoscan
# (anything that is not in git repository must go away)
#gitclean: distclean
gitclean: maintainer-clean
	rm -f  aclocal.m4 ; \
	rm -f  autoscan.log ; \
	rm -fr build/aux/ ; \
	rm -fr build/m4/ ; \
	rm -f  configure ;



### Maintainer targets
#
#
# Bootstrap: simplify maintainer's life
#
.PHONY: bootstrap
bootstrap: maintainer-clean
	./bootstrap.sh
#
#
# Valgrind: run valgrind
#
.PHONY: valgrind
valgrind: all
	valgrind -v \
	--error-exitcode=1 \
	--track-fds=yes \
	--smc-check=all \
	--leak-check=full \
	--undef-value-errors=yes \
	--track-origins=yes \
	./util/snoopy-run-everything ;



### Code coverage
#
if CODE_COVERAGE_ENABLED

coverage-report:
	./dev-tools/libexec/generate-gcov-reports.sh

coverage-clean:
	find . -name "*.gcda" -exec rm {} \;
	find . -name "*.gcov" -exec rm {} \;

coverage: coverage-clean check coverage-report

endif
